package com.xbn.xbnmall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author XBN
 * @date 2020/8/14 14:21
 * @email 78742541@qq.com
 */
public class Cart {

    private List<CartItem> items;
    private Integer countNum;//商品总数量
    private Integer countType;//商品类型的数量
    private BigDecimal totalAmount;//商品总结
    private BigDecimal reduce=new BigDecimal("0.00");//见面的价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count=0;
        if(items!=null&&items.size()>0)
        {
          for (CartItem item:items)
            {
                count+=item.getCount();
            }
        }
        return count;
    }



    public Integer getCountType() {
        int count=0;
        if(items!=null&&items.size()>0)
        {
            for (CartItem item:items)
            {
                count++;
            }
        }
        return count;
    }


        //计算总价
    public BigDecimal getTotalAmount() {
        BigDecimal amount=new BigDecimal("0");
        if(items!=null&&items.size()>0)
        {
            for (CartItem item:items)
            {
                if(item.getCheck())
                {
                    amount.add(item.getTotalPrice());
                }

            }
        }
        return amount.subtract(getReduce());
    }



    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
